package io.xxx.mario.wechaty.request;

import io.xxx.mario.wechaty.RobotRequest;
import io.xxx.mario.wechaty.response.GetLoginQrcodeRobotResponse;
import lombok.Data;
import org.springframework.data.util.Pair;
import org.springframework.http.HttpMethod;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class GetLoginQrcodeRobotRequest implements RobotRequest<GetLoginQrcodeRobotResponse> {

    private Long id;

    private String token;

    @Override
    public HttpMethod httpMethod() {
        return HttpMethod.GET;
    }

    @Override
    public String path() {
        return "/robot/getQRcode";
    }

    @Override
    public Map<String, Object> body() {
        return new HashMap<>() {{
            put("id", id);
            put("token", token);
        }};
    }

    @Override
    public List<Pair<Integer, String>> validate() {
        List<Pair<Integer, String>> errors = new ArrayList<>();
        if (id == null) {
            errors.add(Pair.of(10000001, "机器人ID不存在"));
        }
        if (!StringUtils.hasText(token)) {
            errors.add(Pair.of(10000002, "Wechaty服务token不存在"));
        }
        return errors;
    }

    @Override
    public Class<GetLoginQrcodeRobotResponse> responseType() {
        return GetLoginQrcodeRobotResponse.class;
    }
}
